<template>
  <div>
    <f-table ref='table' size='small' rowKey='processId' :showTotal='true' :showSetting='true' setting-key='payment1' :tableColumns='columns' :multiple='false' :operator='operator' :params='queryParam' :scroll='{x:true}' :api='api.tasktodo' handler='paymentTaskTodoListHandler'>
        <span slot='paymentNo' slot-scope='text, record, index'>
      <span v-clipboard:copy='text' v-clipboard:success='onCopy' style='cursor:pointer'>{{ text }}</span>
        </span>
      <span slot='amountType' slot-scope='text, record, index'>
            <a-tag color='#2db7f5' v-if="text=='SupplierBond'">垫付款</a-tag>
            <a-tag color='#f50' v-if="text=='CbReturn'">退市场保证金</a-tag>
            <a-tag color='#108ee9' v-if="text=='Invoice'">开票税金</a-tag>
            <a-tag color='#87d068' v-if="text=='Settle'">市场结算</a-tag>
            <a-tag color='#87d068' v-if="text=='DrugsPlan'">药品采购</a-tag>
        </span>
      <span slot='action' slot-scope='text, record'>
         <template v-if='record.rowIndex=="合计"'>
           <span>合计</span>
         </template>
          <template v-if='record.rowIndex!="合计"'>
            <a v-if="record.endTime==''&&record.assignee!=''&& record.assignee!=''" @click='$refs.drawer.showDrawer(record)'>办理</a>
            <a v-if="record.assignee==''||record.assignee==''" @click='claimTask(record)'>认领</a>
             <a-divider type='vertical' />
              <a href='javascript:;' @click="$refs['orderInfoDrawer'].showDrawer(record)" v-if="record.amountType=='SupplierBond'">查看</a>
              <a href='javascript:;' @click="$refs['invoice'].showDrawer(record,'form2')" v-if="record.amountType=='Invoice'">查看</a>
              <a href='javascript:;' @click="$refs['settle'].showDrawer(record,'form2')" v-if="record.amountType=='Settle'">查看</a>
             <a href='javascript:;' @click="$refs['cbreturn'].showDrawer(record,'form2')" v-if="record.amountType=='CbReturn'">查看</a>
              <a-divider type='vertical' />
          </template>
          <a-dropdown v-if='record.rowIndex!="合计"'>
            <a class='ant-dropdown-link'>更多 <a-icon type='down' /></a>
            <a-menu slot='overlay'>
               <a-menu-item v-if="record.assignee===$store.getters.userInfo.nickName && record.endTime==''">
                <a href='javascript:;' @click='unClaimTask(record)'>取消认领</a>
              </a-menu-item>
                <a-menu-item>
                <a href='javascript:;' @click='processImg(record)'>流程图</a>
              </a-menu-item>
               <a-menu-item v-if='superAdmin'>
                <a href='javascript:;' @click='deleteProcessInstance(record)'>删除</a>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>
    </f-table>
    <task-todo-drawer ref='drawer' @success='onLoad' handler-name='payFormTaskDataHandler'></task-todo-drawer>
    <process-image ref='processImg' v-if='processImageVisible' :visible.sync='processImageVisible' :processInstanceId='processInstanceId'></process-image>
    <order-info-drawer ref='orderInfoDrawer'></order-info-drawer>
    <invoice-drawer ref='invoice'></invoice-drawer>
    <settle-drawer ref='settle'></settle-drawer>
    <cbreturn-drawer ref='cbreturn'></cbreturn-drawer>
  </div>
</template>
<script>

import api from "./../js/api"
import TaskTodoDrawer from "./../tasktodo_drawer"
import ProcessImage from "../../process/process_image"
import InvoiceDrawer from "../../../business/order/invoice/invoice_drawer"
import SettleDrawer from "../../../business/order/settle/settle_drawer"
import CbreturnDrawer from "../../../business/order/cbreturn/cbreturn_drawer"
import OrderInfoDrawer from "../../../business/order/order_info_drawer"

export default {
  name: "TableList",
  components: {
    OrderInfoDrawer,
    InvoiceDrawer,
    ProcessImage,
    SettleDrawer,
    TaskTodoDrawer,
    CbreturnDrawer
  },
  data() {
    let me = this
    //操作按钮
    let operator = []

    return {
      api: Object.assign(api, this.api),
      //列表初始化查询参数
      queryParam: {},
      processInstanceId: "",
      superAdmin: this.superAdmin,
      processImageVisible: false,
      // 表头
      columns: [
        {
          title: "序号",
          width: "60px",
          fixed: "left",
          align: "center",
          customRender: (text, record, index) => index + 1
        },
        {
          title: "操作",
          fixed: "left",
          align: "center",
          dataIndex: "action",
          width: "160px",
          scopedSlots: { customRender: "action" }
        },
        {
          title: "单号",
          align: "center",
          width: "130px",
          dataIndex: "paymentNo",
          scopedSlots: { customRender: "paymentNo" }
        },

        {
          title: "单据类型",
          align: "center",
          dataIndex: "amountType",
          scopedSlots: { customRender: "amountType" },
          filters: [
            {
              text: "垫付款",
              value: "SupplierBond"
            },
            {
              text: "市场结算",
              value: "Settle"
            },
            {
              text: "退保证金",
              value: "CbReturn"
            },
            {
              text: "退垫付款",
              value: "SbReturn"
            },
            {
              text: "开票税金",
              value: "Invoice"
            },
            {
              text: "药品采购",
              value: "DrugsPlan"
            }
          ],
          filterMultiple: false
        },
        {
          title: "收款单位",
          align: "center",
          dataIndex: "unitName"
        },
        {
          title: "收款人",
          align: "center",
          dataIndex: "linkMan"
        },
        {
          title: "部门",
          align: "center",
          dataIndex: "deptName"
        },
        {
          title: "购货方",
          align: "center",
          dataIndex: "customName"
        },
        {
          title: "供货方",
          align: "center",
          dataIndex: "supplierName"
        },
        {
          title: "申请金额",
          align: "center",
          dataIndex: "amount",
          needTotal: true
        },
        {
          title: "制单人",
          align: "center",
          dataIndex: "nickName"
        },
        {
          title: "申请日期",
          align: "center",
          dataIndex: "amountDate"
        },
        {
          title: "审批状态",
          align: "center",
          dataIndex: "taskName",
          filters: [
            {
              text: "内勤部长审核",
              value: "内勤部长审核"
            }, {
              text: "出纳支付",
              value: "出纳支付"
            }, {
              text: "会计核算",
              value: "会计核算"
            },
            {
              text: "出纳确认",
              value: "出纳确认"
            },
            {
              text: "采购部长确认",
              value: "采购部长确认"
            },
            {
              text: "采购部长审核",
              value: "采购部长审核"
            },
            {
              text: "支付申请",
              value: "支付申请"
            },
            {
              text: "总经理审批",
              value: "总经理审批"
            }
          ],
          filterMultiple: false
        },
        {
          title: "创建日期",
          align: "center",
          dataIndex: "createTime"
        }
      ],
      operator: operator
    }
  },
  created() {
  },
  methods: {
    onLoad() {
      this.$refs.table.refresh()
    },
    onCopy() {
      this.$message.success("复制成功!")
    },
    claimTask(task) {
      this.http.post(this, {
        url: this.api.tasktodo.claim,
        data: {
          taskId: task.taskId
        },
        success(me, data) {
          me.$refs["table"].refresh(false)
        }
      })
    },
    processImg(task) {
      this.processInstanceId = task.processInstanceId
      this.processImageVisible = true
    },
    /**
     * 查询事件
     * @param searchParams
     */
    searchTable(searchParams) {
      this.queryParam = Object.assign(this.queryParam, searchParams)
      this.$refs.table.refresh(true, searchParams)
    },
    deleteProcessInstance(task) {
      this.http.confirm(this, {
        content: "确认删除吗?",
        url: api.processInstance.remove,
        data: {
          ids: task.processInstanceId,
          cascade: true
        },
        success: function(me, data) {
          me.$refs["table"].refresh(false)
        }
      })
    },
    unClaimTask(task) {
      this.http.put(this, {
        url: this.api.tasktodo.unclaim,
        data: {
          taskId: task.taskId
        },
        success(me, data) {
          me.$refs["table"].refresh(false)
        }
      })
    }
  }
}
</script>
